<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件的嵌套</title>
    <script src="../../js/vue.js"></script>
</head> 
<body>

    <div id="root">
        
    </div>
    <script type="text/javascript">
        Vue.config.productionTip = false;
        
        //创建hello 组件
        const helloword = Vue.extend({
            template: `
                <div>
                    <h2>{{nihao}} </h2>
                    <h2>{{age}} </h2>
                </div>
            `,
            data(){
                return {
                    nihao: '你好尚硅谷',
                    age: 23
                }
            },

        })

        // 创建student组件
        const student = Vue.extend({
            template: `
                <div>
                    <h1>学生名称 {{name}}</h1>
                    <h1>学生年龄 {{age}}</h1>
                    <hello-word></hello-word>
                </div>
            `,
            data(){
                return {
                    name: '法外狂徒张三',
                    age: 34
                }
            },
            components: {
                'hello-word': helloword
            }
        })


        // 第一步创建school组件
        const school = Vue.extend({
            template: `
                <div>
                    <h1>学校名称 {{schoolName}}</h1>
                    <h1>学校地址 {{address}}</h1>
                    <button @click='tip'>点我提示学校名称</button>
                    <student></student>
                </div>
            `,
            data(){
                return {
                    schoolName: '尚硅谷',
                    address: '成都'
                }
            },
            components: {
                student
            },
            methods: {
                tip(){
                    alert(this.schoolName)
                }
            }
        })
        

        // 定义app组件
        const app = Vue.extend({
            template:`
                <div>
                    <hr/>
                    <school/>
                    <hr/>
                    <student/>
                    <hr>
                </div>
            `,
            components: {
                school,
                student
            }

        })
        
        // 创建vm
        const vm = new Vue({
            template: `<app></app>`,
            el: '#root',
            // 注册组件
            data: {
                msg: '欢迎学习Vue'
            },
            components:{
                app
            },

        })


    </script>
</body>
</html>